﻿<?xml version="1.0" encoding="utf-8"?>
<!--
        作者：          liuleyi
        更新时间：      20170227
        用途：          生成存储过程默认模板
-->
<xsl:stylesheet version="2.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xmlns:fn="http://www.w3.org/2005/xpath-functions">
	<xsl:output method="text" indent="no" encoding="utf-8" byte-order-mark="no"/>  
	<xsl:template match="/">
	<xsl:result-document encoding="utf-8" method="text" href="./generate/sql/proc/Procedure.sql">
	<xsl:variable name="StringTypeDefine" select="document('../model/0101_StringTypeDefine.xml')"/>
	<xsl:variable name="EnumTypeDefine" select="document('../model/0102_EnumTypeDefine.xml')"/>
	<xsl:variable name="BooleanTypeDefine" select="document('../model/0103_BooleanTypeDefine.xml')"/>
	<xsl:variable name="DateTypeDefine" select="document('../model/0104_DateTypeDefine.xml')"/>
	<xsl:variable name="NumberTypeDefine" select="document('../model/0105_NumberTypeDefine.xml')"/>
	<xsl:variable name="IntegerTypeDefine" select="document('../model/0106_IntegerTypeDefine.xml')"/>
<xsl:for-each select="Procedures/Procedure">
CREATE PROCEDURE <xsl:value-of select="@code"/><xsl:for-each select="Request">(
<xsl:for-each select="Column">
<xsl:variable name="typeTable" select="@name"/>
PI_<xsl:value-of select="$typeTable"/><xsl:for-each select="$StringTypeDefine//String[@typename=$typeTable]">  pkg_String_Type.<xsl:value-of select="@typename"/>
</xsl:for-each>
<xsl:for-each select="$EnumTypeDefine//Enum[@typename=$typeTable]">  Pkg_Enum_Type.<xsl:value-of select="@typename"/>
</xsl:for-each>
<xsl:for-each select="$BooleanTypeDefine//Boolean[@typename=$typeTable]">  pkg_Boolean_Type.<xsl:value-of select="@typename"/>
</xsl:for-each>
<xsl:for-each select="$DateTypeDefine//Date[@typename=$typeTable]">  pkg_Date_Type.<xsl:value-of select="@typename"/>
</xsl:for-each>
<xsl:for-each select="$NumberTypeDefine//Number[@typename=$typeTable]">  pkg_Number_Type.<xsl:value-of select="@typename"/>
</xsl:for-each>
<xsl:for-each select="$IntegerTypeDefine//Integer[@typename=$typeTable]">  pkg_Integer_Type.<xsl:value-of select="@typename"/>
</xsl:for-each><xsl:if test="position()!=last()">,</xsl:if><xsl:for-each select="$StringTypeDefine//String[@typename=$typeTable]">--<xsl:value-of select="@label"/>
</xsl:for-each>
<xsl:for-each select="$EnumTypeDefine//Enum[@typename=$typeTable]">--<xsl:value-of select="@label"/>
</xsl:for-each>
<xsl:for-each select="$BooleanTypeDefine//Boolean[@typename=$typeTable]">--<xsl:value-of select="@label"/>
</xsl:for-each>
<xsl:for-each select="$DateTypeDefine//Date[@typename=$typeTable]">--<xsl:value-of select="@label"/>
</xsl:for-each>
<xsl:for-each select="$NumberTypeDefine//Number[@typename=$typeTable]">--<xsl:value-of select="@label"/>
</xsl:for-each>
<xsl:for-each select="$IntegerTypeDefine//Integer[@typename=$typeTable]">--<xsl:value-of select="@label"/>
</xsl:for-each>
</xsl:for-each>
)
</xsl:for-each>
is
/*
  名称:<xsl:value-of select="@code"/>
  功能描述:<xsl:value-of select="@label"/>
-----------------------------------------------------------
  修改记录
    版本号   |编辑时间          |编辑人       |修改描述
    1         |<xsl:value-of select="current-dateTime()"/>|自动化脚本   |创建此程式

-----------------------------------------------------------
-----------------------------------------------------------
*/
  --固定变量声明区域--START
  v_Errorcode Pkg_String_Type.Log_Code;
  v_Errormsg  Pkg_String_Type.Log_Msg;
  v_Expcetion EXCEPTION;
  v_Objectid  VARCHAR2(30);
  v_Etl_Date Pkg_Date_Type.Etl_Date;
  v_Rowcnt   Pkg_Integer_Type.Rowcnt;
  --固定变量声明区域--END
  --
BEGIN
  --固定变量初始化--START
  v_Rowcnt    := 0;
  v_Errorcode := 0;
  v_Errormsg := '';
  v_Objectid := Pkg_Tool.Getobjid;
  v_Etl_Date  := SYSDATE;
--代码区 start


--代码区 end
  
--日志记录 start
INSERT INTO t_Yjgk_Job_Log
    (Logseq, Job_Name, Flag, Log_Code, Log_Msg, Zxsj, Etl_date)
  VALUES
    (Seqlog.Nextval,
     v_Objectid,
     pkg_Boolean_Type.FLAG_True,
     v_Errorcode,
     v_Errormsg,
     v_Etl_Date,
     v_Etl_Date);
  COMMIT;
 --日志记录 end 
EXCEPTION
  --固定异常捕捉--START
  WHEN v_Expcetion THEN
    ROLLBACK;
    p_Lg_Raise_Error(Pi_Errorcode => v_Errorcode,
                     Pi_Errormsg  => v_Errormsg,
                     Pi_Objectid  => v_Objectid);
  
  WHEN OTHERS THEN
    ROLLBACK;
    v_Errorcode := SQLCODE;
    v_Errormsg  := SQLERRM;
    p_Lg_Raise_Error(Pi_Errorcode => v_Errorcode,
                     Pi_Errormsg  => v_Errormsg,
                     Pi_Objectid  => v_Objectid);
    RAISE;
    --固定异常捕捉--END
END;
/</xsl:for-each>
</xsl:result-document></xsl:template>  
</xsl:stylesheet>